"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// @jhao 包含随机种子的随机函数
class RandomUtil {
    static getRandomSeed() {
        let seed = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
        // Logger.log("getRandomSeed=", seed, Number.MAX_SAFE_INTEGER)
        return seed;
    }
    static seedRandom(min = 0, max = 1) {
        this.seed = (this.seed * 9301 + 49297) % 233280;
        let rnd = this.seed / 233280.0;
        let result = min + rnd * (max - min);
        // Logger.log("seedRandom=", result)
        return result;
    }
    /** 随机minNum到maxNum的数字 （包含maxNum） */
    static nextInt(minNum, maxNum, seed = RandomUtil.getRandomSeed()) {
        this.seed = seed;
        return Math.floor(this.seedRandom() * (maxNum - minNum + 1) + minNum);
    }
    static nextNumber(minNum, maxNum, seed = RandomUtil.getRandomSeed()) {
        this.seed = seed;
        return this.seedRandom() * (maxNum - minNum) + minNum;
    }
    static nextSign(seed = RandomUtil.getRandomSeed()) {
        if (this.nextBoolean(seed)) {
            return 1;
        }
        return -1;
    }
    static nextBoolean(seed = RandomUtil.getRandomSeed()) {
        this.seed = seed;
        let temp = this.nextInt(0, 1, seed);
        if (temp = 0) {
            return true;
        }
        return false;
    }
    static randomArr(nowArr, needNum, seed = RandomUtil.getRandomSeed()) {
        let tempArr = nowArr.concat();
        let resultArr = [];
        for (let index = 0; index < needNum; index++) {
            if (tempArr.length <= 0) {
                break;
            }
            let randomIndex = RandomUtil.nextInt(0, tempArr.length - 1, seed);
            resultArr.push(tempArr.splice(randomIndex, 1)[0]);
        }
        return resultArr;
    }
    static randomItem(nowArr, seed = RandomUtil.getRandomSeed()) {
        return this.randomArr(nowArr, 1, seed)[0];
    }
    static randomIndexByPercent(rateList = [100, 100, 100], seed = RandomUtil.getRandomSeed()) {
        let tempList = [];
        let totalTemp = 0;
        for (let i = 0; i < rateList.length; i++) {
            totalTemp += rateList[i];
            tempList[i] = totalTemp;
        }
        let randomTemp = this.nextInt(0, totalTemp, seed);
        let resultIndex = tempList.length - 1;
        for (let i = 0; i < tempList.length; i++) {
            if (randomTemp <= tempList[i]) {
                resultIndex = i;
                break;
            }
        }
        return resultIndex;
    }
}
exports.default = RandomUtil;
RandomUtil.seed = 0;
